//
//  BK_my_detailAddressCell.m
//  bestkeep
//
//  Created by bj on 2016/11/10.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BK_my_detailAddressCell.h"
#import "BKMyCommon.h"
#import "Masonry.h"
#import "BK_Adress_Tool.h"

@implementation BK_my_detailAddressCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)initlizeValue:(CellModel *)model {
    self.optionLabel.text = model.title;
    self.delegate = model.delegate;
    self.optionTextField.text = model.selectorString;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = BK_MY_COLOR_06;
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left);
            make.right.equalTo(self.contentView.mas_right);
            make.top.equalTo(self.contentView.mas_top);
            make.height.equalTo(@(1.5));
        }];
        _optionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_optionLabel];
        _optionLabel.font = [UIFont systemFontOfSize:15];
        _optionLabel.textColor = BK_MY_COLOR_07;
        [_optionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).mas_offset(Address_BackGauge);
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.width.equalTo(@(66));
        }];
        
        _optionTextField = [[UITextField alloc] initWithFrame:CGRectZero];
        self.optionTextField.delegate = self;
        self.optionTextField.placeholder = @"街道、楼牌号等";
        self.optionTextField.returnKeyType = UIReturnKeyDone;
        [self.optionTextField addTarget:self action:@selector(textValueChanged:) forControlEvents:UIControlEventEditingChanged];
        [self.contentView addSubview:_optionTextField];
        _optionTextField.font = [UIFont systemFontOfSize:15];
        [_optionTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(self.contentView.frame.size.height / 2));
            make.left.equalTo(_optionLabel.mas_right).mas_offset(15);
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.right.equalTo(self.contentView.mas_right).mas_offset(-Address_BackGauge);
        }];
    }
    return self;
}

- (void)textValueChanged:(UITextField *)textField{
    if ([self.delegate respondsToSelector:@selector(detailAddressInformation:)]) {
        [self.delegate detailAddressInformation:self.optionTextField.text];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
